package cn.codeforfun.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Package cn.codeforfun.util
 * Project cloud-websocket
 * Author WangBin
 * Email bin.wang12@pactera.com
 * Created on 2017/8/14 0014 16:15
 * version 1.0.0
 */
public class JSONUtil {
  public static String toJson(Object obj) {
    if (obj == null) return null;
    ObjectMapper om = new ObjectMapper();
    try {
      return om.writeValueAsString(obj);
    } catch (JsonProcessingException e) {
      e.printStackTrace();
      return null;
    }
  }
}
